package com.cac.demo.service.wmsreturnapply.impl;

import com.cac.demo.dao.materialScan.WmsDeliverPlanDao;
import com.cac.demo.dao.wmsreturnapply.WmsReturnApplyDao;
import com.cac.demo.entity.materialScan.WmsDeliverPlanDTO;
import com.cac.demo.entity.wmsReturnApply.WmsReturnApplyDTO;
import com.cac.demo.service.wmsreturnapply.WmsReturnApplyService;
import com.cac.demo.util.adapter.ComUtil;
import com.cac.demo.util.adapter.DaoException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class WmsReturnApplyServiceImpl implements WmsReturnApplyService {
    @Autowired
    private WmsReturnApplyDao wmsReturnApplyDao;
    @Autowired
    private WmsDeliverPlanDao wmsDeliverPlanDao;
    @Transactional
    @Override
    public WmsDeliverPlanDTO searchDeliverPlan(String wmsDeliveryPlanId) {
        try {
            WmsDeliverPlanDTO wmsDeliverPlanDTO = wmsDeliverPlanDao.searchDeliverPlan(wmsDeliveryPlanId);
            //记录日志
            if (wmsDeliverPlanDTO != null) {
            }
            return wmsDeliverPlanDTO;
        } catch (Exception e) {
            throw new DaoException(e.getMessage(), e);
        }
    }
    @Transactional
    @Override
    public int insertWmsReturnApply(WmsDeliverPlanDTO wmsDeliverPlanDTO) {
        try{
            String WmsReturnApplyId = ComUtil.getId();
            String status = "1";
            return wmsReturnApplyDao.insertWmsReturnApply(wmsDeliverPlanDTO,WmsReturnApplyId,status);
        }catch (Exception e){
            throw new DaoException(e.getMessage());
        }
    }
    @Transactional
    @Override
    public WmsReturnApplyDTO selectReturnApply(String id){
        try{
            return wmsReturnApplyDao.selectReturnApply(id);
        }catch (Exception e){
            throw new DaoException(e.getMessage());
        }
    }
    @Transactional
    @Override
    public int changeReturnStatus(String returnStatus, String id){
        try{
            if(returnStatus.equals("1")){
                returnStatus = returnStatus.replace('1','3');
            }else if(returnStatus.equals("3")){
                returnStatus = returnStatus.replace('3','4');
            }else if(returnStatus.equals("4")){
                returnStatus = returnStatus.replace('4','6');
            }
            return wmsReturnApplyDao.changeReturnStatus(returnStatus,id);
        }catch (Exception e){
            throw new DaoException(e.getMessage());
        }
    }

}
